﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Snippet_saver
{
    public partial class Show_big : Form
    {
        string fileselected;
        mainform mainform;
        public Show_big(string _fileselected,mainform callingform)
        {
            fileselected = _fileselected;
            mainform = callingform;
            InitializeComponent();
        }


        private void Show_big_Load(object sender, EventArgs e)
        {
            string openfilethingy = "./data/" + fileselected;
            try
            {
                richTextBox1.LoadFile(openfilethingy, RichTextBoxStreamType.PlainText);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message,"Error occured.",MessageBoxButtons.OK,MessageBoxIcon.Error);
            }

        }

        private void button_save_Click(object sender, EventArgs e)
        {
            try
            {
                richTextBox1.SaveFile("./data/" + fileselected, RichTextBoxStreamType.PlainText);
                mainform.statuslabel.Text = "File succesfully saved.";
                string openfilethingy = "./data/" + fileselected;
                mainform.richTextBox_quickview.LoadFile(openfilethingy, RichTextBoxStreamType.PlainText);
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error has occured, see below.\n\n" + ex.ToString());
                mainform.statuslabel.Text = "Error occured while saving file.";
            }
        }
    }
}
